// pages/user/user.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    username: "请登录",
    headurl: "https://api.fracher21.top/spotit-static/img/common/default_user.png",
    motto: "欢迎使用",
    mainList: [
      {
        text: "帖子收藏",
        path: "/pages/user/stars/stars",
        icon: "/images/yhy/star.png"
      },
      {
        text: "动物收藏",
        path: "/pages/user/animals/animals",
        icon: "/images/yhy/animal.png"
      },
      {
        text: "我的帖子",
        path: "/pages/user/myposts/myposts",
        icon: "/images/yhy/mypost.png",
      },
      {
        text: "历史浏览",
        path: "/pages/user/history/history",
        icon: "/images/yhy/history.png"
      },
      {
        text: "设置",
        path: "/pages/user/settings/settings",
        icon: "/images/yhy/settings.png"
      },
      {
        text: "关于我们",
        path: "/pages/user/about/about",
        icon: "/images/yhy/about.png"
      }
    ]
  },

  profileClick: function () {
    wx.navigateTo({
      url: '/pages/user/userDetail/userDetail?user_id=' + this.data.id,
    })
  },

  updateData() {
    let that = this;
    let app = getApp();
    wx.request({
      url: 'https://api.fracher21.top/spotit/getuserinfo',
      method: 'GET',
      data: {
        token: app.globalData.token,
      },
      success: (res) => {
        let data = res.data;
        that.setData({
          username: data.name,
          headurl: data.head,
          motto: data.motto,
          id: data.id,
        })
      }
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.updateData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.updateData();
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 2
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})